import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '联系人',
    align: "center",
    sorter: true,
    dataIndex: 'reqContract_dictText'
  },
  {
    title: '电话',
    align: "center",
    sorter: true,
    dataIndex: 'mobile'
  },
  {
    title: '邮箱',
    align: "center",
    sorter: true,
    dataIndex: 'email'
  },
  {
    title: '启用',
    align: "center",
    sorter: true,
    dataIndex: 'status',
    customRender:({text}) => {
       return  render.renderSwitch(text, [{text:'是',value:'Y'},{text:'否',value:'N'}]);
     },
  },
];

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "联系人",
    field: 'reqContract',
    component: 'JSearchSelect',
    componentProps:{
      dict: "sys_user,realname,username"
    },
    //colProps: {span: 6},
  },
  {
    label: "电话",
    field: 'mobile',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "邮箱",
    field: 'email',
    component: 'Input',
    //colProps: {span: 6},
  },
];

//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '联系人',
    field: 'reqContract',
    component: 'JSearchSelect',
    componentProps:{
      dict: "sys_user,realname,username"
    },
    dynamicRules: ({model,schema}) => {
      return [
              { required: true, message: '请输入联系人!'},
             ];
    },
  },
  {
    label: '电话',
    field: 'mobile',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
              { required: true, message: '请输入电话!'},
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
             ];
    },
  },
  {
    label: '邮箱',
    field: 'email',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
              { required: true, message: '请输入邮箱!'},
              { pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/, message: '请输入正确的电子邮件!'},
             ];
    },
  },
  {
    label: '启用',
    field: 'status',
    component: 'JSwitch',
    componentProps:{
    },
    dynamicRules: ({model,schema}) => {
      return [
              { required: true, message: '请输入启用!'},
             ];
    },
  },
	// TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  reqContract: {title: '联系人',order: 0,view: 'sel_search', type: 'string',dictTable: "sys_user", dictCode: 'username', dictText: 'realname',},
  mobile: {title: '电话',order: 1,view: 'text', type: 'string',},
  email: {title: '邮箱',order: 2,view: 'text', type: 'string',},
  status: {title: '启用',order: 3,view: 'switch', type: 'string',},
};
